package com.vvitt.kotlinhiltcarhome.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.paging.LoadState
import androidx.paging.LoadStateAdapter
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.vvitt.kotlinhiltcarhome.databinding.ItemNetworkStateBinding

/**
 * @ClassName FooterAdapter
 * @author please call me police uncel
 * @since 2023/5/26.
 * @email 110
 * @Version: V1.0.0
 * @desciption 加载更多的adapter
 **/
class FooterAdapter(
    private val carBrandAdapter: CarBrandAdapter,
    val context: Context
) : LoadStateAdapter<NetWorkStateItemViewHolder>(){
    override fun onBindViewHolder(holder: NetWorkStateItemViewHolder, loadState: LoadState) {
        //水平居中
        val params = holder.itemView.layoutParams
        if (params is StaggeredGridLayoutManager.LayoutParams) {
            params.isFullSpan = true
        }
        holder.bindData(loadState)
    }

    override fun onCreateViewHolder(parent: ViewGroup, loadState: LoadState): NetWorkStateItemViewHolder {
        val binding = ItemNetworkStateBinding.inflate(LayoutInflater.from(context), parent, false)
        return NetWorkStateItemViewHolder(binding) { carBrandAdapter.retry() }
    }


}